package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-21 00:43
 **/
public class LeetCode1154 {

    public int dayOfYear(String date) {
        int year = Integer.parseInt(date.substring(0, 5));
        int month = Integer.parseInt(date.substring(5, 7));
        int day = Integer.parseInt(date.substring(8));

        //每月的数量,闰年的二月会多出一天(闰年: 年是400的倍数,或者年是4的倍数且不是100的倍数)
        int[] amount = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            ++amount[1];
        }

        int res = 0;
        for (int i = 0; i < month - 1; i++) {
            res += amount[i];
        }

        return res + day;
    }

}
